/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
AOS.utils.namespace( "AOS.map" );
AOS.map = new Object();

AOS.map.mapClickedX = -1;
AOS.map.mapClickedY = -1;
AOS.map.mapSquareSelector = false;
AOS.map.mapDragging = false;

AOS.map.initialize = function() {
	AOS.map.sectorsPerRow = Math.round( AOS.map.width / AOS.map.sectorWidth );
	
	// read out the max number of locations
	AOS.map.maxLocations = document.getElementById( 'max-locations' ).innerHTML;
	
	AOS.map.maptable = document.getElementById( 'maptable' );
	AOS.map.coords = document.getElementById( 'map_coords' );
	var square_size = 10;
	var top_start = 3;
	var left_start = 2;

	YAHOO.util.Dom.setStyle( AOS.map.maptable, "width", ( ( Math.round( AOS.map.width / square_size ) * square_size )* 14 ) + 'px' );
	YAHOO.util.Dom.setStyle( AOS.map.maptable, "height", ( ( Math.round( AOS.map.height / square_size ) * square_size )* 14 ) + 'px' );
	
	var sectorClass = 0;
	var emptySectorClass = 0;
	
	for( p = 0; p < AOS.map.height / AOS.map.sectorHeight; p ++ ) {
		for( i = 0; i < AOS.map.width / AOS.map.sectorWidth; i ++ ) {
			var element = document.createElement( 'div' );
			YAHOO.util.Dom.addClass( element, 'sectorBorder' );
			if( p % 3 == 2 || i % 3 == 2 ) {
				if( emptySectorClass % 3 == 0 ) {
					YAHOO.util.Dom.addClass( element, 'empty-sector-1-no-image' );
				}
				else if( emptySectorClass % 3 == 1 ) {
					YAHOO.util.Dom.addClass( element, 'empty-sector-2-no-image' );
				}
				else {
					YAHOO.util.Dom.addClass( element, 'empty-sector-3-no-image' );
				}
				emptySectorClass ++;
			}
			else {
				if( sectorClass % 3 == 0 ) {
					YAHOO.util.Dom.addClass( element, 'full-sector-1-no-image' );
				}
				else if( sectorClass % 3 == 2 ) {
					YAHOO.util.Dom.addClass( element, 'full-sector-2-no-image' );
				}
				else {
					YAHOO.util.Dom.addClass( element, 'full-sector-3-no-image' );
				}
				sectorClass ++;
			}
			YAHOO.util.Dom.setStyle( element, 'top', ( top_start + AOS.map.sectorHeight * p * 14 ) + "px" );
			YAHOO.util.Dom.setStyle( element, 'left', ( left_start + AOS.map.sectorWidth * i * 14 ) + "px" );
			YAHOO.util.Dom.setStyle( element, 'width', ( AOS.map.sectorWidth * 14 ) + "px" );
			YAHOO.util.Dom.setStyle( element, 'height', ( AOS.map.sectorHeight * 14 ) + "px" );
			AOS.map.maptable.appendChild( element );
		}
	}
	
	YAHOO.util.Dom.setStyle( AOS.map.maptable, "left", AOS.map.start_x * -14 + "px" );
	YAHOO.util.Dom.setStyle( AOS.map.maptable, "top", AOS.map.start_y * -14 + "px" );
	
	AOS.map.dd = new YAHOO.util.DD( AOS.map.maptable, { dragOnly: true } );
	AOS.map.dd.scroll = false;
	//alert( dd.dragElId );
	AOS.map.dd.setInitPosition( AOS.map.start_x * -14, AOS.map.start_y * -14 );
	//alert( 'dd.setXConstraint( ' + ( ( width - start_x ) * 14 ) + ', ' + ( start_x * 14 ) + ' );' );
	AOS.map.dd.setXConstraint( ( AOS.map.width - AOS.map.start_x - AOS.map.display ) * 14 + 15, AOS.map.start_x * 14 );
	//alert( 'dd.setYConstraint( ' + ( start_y * 14 ) + ', ' + ( ( height - start_y ) * 14 ) + ' );' );
	AOS.map.dd.setYConstraint( ( AOS.map.height - AOS.map.start_y - AOS.map.display ) * 14 + 5, AOS.map.start_y * 14 );
	
	AOS.map.dd.startDrag = function() {
		YAHOO.util.Dom.setStyle( AOS.map.maptable, "cursor", "move" );
		AOS.map.mapDragging = true;
		AOS.map.oldX = AOS.map.x;
		AOS.map.oldY = AOS.map.y;		
   };
	AOS.map.dd.endDrag = function() {
		YAHOO.util.Dom.setStyle( AOS.map.maptable, "cursor", "pointer" );
		if( AOS.map.oldX != AOS.map.x || AOS.map.oldY != AOS.map.y ) {
			AOS.map.addInformation( AOS.map.x, AOS.map.y );
		}
	};
	AOS.map.dd.onDrag = function() {
		AOS.map.updateCoords();
	};
    
	AOS.map.updateCoords();
	AOS.map.addInformation( AOS.map.x, AOS.map.y );

	AOS.map.mapOverlay = document.getElementById( 'map_overlay' );
	YAHOO.util.Event.addListener( AOS.map.maptable, 'click', AOS.map.mapClicked )
	AOS.map.getSquareInfo( AOS.map.centerX, AOS.map.centerY );
	if( !AOS.map.mapSquareSelector ) {
		AOS.map.mapSquareSelector = document.createElement( "div" );
		YAHOO.util.Dom.addClass( AOS.map.mapSquareSelector, "square-selector" );
		AOS.map.maptable.appendChild( AOS.map.mapSquareSelector );
	}
	
	YAHOO.util.Dom.setX( AOS.map.mapSquareSelector, Math.round( AOS.map.centerX * 14 ) + YAHOO.util.Dom.getX( AOS.map.maptable ) - 1 );
	YAHOO.util.Dom.setY( AOS.map.mapSquareSelector, Math.round( AOS.map.centerY * 14 ) + YAHOO.util.Dom.getY( AOS.map.maptable ) + 0 );

	// Update new location
	var lis = YAHOO.util.Dom.getElementsByClassName( '', 'li', 'locations-list' );
	var uncounted = YAHOO.util.Dom.getElementsByClassName( 'dont-count-this', 'li', 'locations-list' );
	var element = document.getElementById( "new-location" );
	if( !element ) {
		element = document.createElement( "span" );
		element.id = "new-location";
		document.getElementById( "locations-container" ).appendChild( element );
	}
	if( lis.length - uncounted.length < AOS.map.maxLocations ) {
		element.innerHTML = "<a href=\"javascript:void(null);\" onclick=\"AOS.map.addLocation(" + AOS.map.centerX + ", " + AOS.map.centerY + ")\">" + AOS.map.storeLocationText + "</a>: (" + AOS.map.centerX + ", " + AOS.map.centerY + ")";
	}
	else {
		element.innerHTML = "(" + AOS.map.centerX + ", " + AOS.map.centerY + ")";
	}
	
}

AOS.map.mapClicked = function( e ) {
	if( !AOS.map.mapDragging ) {
		AOS.map.mapClickedX = Math.floor( ( ( e.clientX + YAHOO.util.Dom.getDocumentScrollLeft() ) - YAHOO.util.Dom.getX( AOS.map.maptable ) ) / 14.0 );
		AOS.map.mapClickedY = Math.floor( ( ( e.clientY + YAHOO.util.Dom.getDocumentScrollTop() ) - YAHOO.util.Dom.getY( AOS.map.maptable ) ) / 14.0 );
		
		if( !AOS.map.mapSquareSelector ) {
			AOS.map.mapSquareSelector = document.createElement( "div" );
			YAHOO.util.Dom.addClass( AOS.map.mapSquareSelector, "square-selector" );
			AOS.map.maptable.appendChild( AOS.map.mapSquareSelector );
		}
		
		YAHOO.util.Dom.setX( AOS.map.mapSquareSelector, Math.round( AOS.map.mapClickedX * 14 + YAHOO.util.Dom.getX( AOS.map.maptable ) - 1 ) );
		YAHOO.util.Dom.setY( AOS.map.mapSquareSelector, ( Math.round( AOS.map.mapClickedY * 14 ) + YAHOO.util.Dom.getY( AOS.map.maptable ) + 0 ) );
		
		AOS.map.getSquareInfo( AOS.map.mapClickedX, AOS.map.mapClickedY );

		//Update new location
		var lis = YAHOO.util.Dom.getElementsByClassName( '', 'li', 'locations-list' );
		var element = document.getElementById( "new-location" );
		if( !element ) {
			element = document.createElement( "span" );
			element.id = "new-location";
			document.getElementById( "locations-container" ).appendChild( element );
		}
		if( lis.length < AOS.map.maxLocations ) {
			element.innerHTML = "<a href=\"javascript:void(null);\" onclick=\"AOS.map.addLocation(" + AOS.map.mapClickedX + ", " + AOS.map.mapClickedY + ")\">" + AOS.map.storeLocationText + "</a>: (" + AOS.map.mapClickedX + ", " + AOS.map.mapClickedY + ")";
		}
		else {
			element.innerHTML = "(" + AOS.map.mapClickedX + ", " + AOS.map.mapClickedY + ")";
		}
	}
	AOS.map.mapDragging = false;
}

AOS.map.updateCoords = function() {
	AOS.map.x = -1 * Math.round( AOS.map.maptable.style.left.substring( 0, AOS.map.maptable.style.left.length - 2 ) / 14.0 );
   AOS.map.y = -1 * Math.round( AOS.map.maptable.style.top.substring( 0, AOS.map.maptable.style.top.length - 2 ) / 14.0 );
	AOS.map.coords.innerHTML = 'Showing: x: ' + AOS.map.x + ' - ' + ( AOS.map.x + AOS.map.display ) + ', y: ' + AOS.map.y + ' - ' + ( AOS.map.y + AOS.map.display );
}

AOS.map.addInformation = function( xGet, yGet ) {
	if( xGet == 'complete' ) {
		xGet = AOS.map.x;
		yGet = AOS.map.y;
	}
	AOS.map.coords.innerHTML = AOS.map.coords.innerHTML + ' (Retrieving map information)';
	YAHOO.util.Connect.asyncRequest( 'GET', 'get_locations.php?' + "x=" + xGet + "&y=" + yGet, AOS.map.infoCallback, null );
}

AOS.map.plotArmies = function( info ) {
	info[0] = null;
	//alert( info );
	for( q in info ) {
		if( info[q] != null ) {
			var items = info[q].split( '|' );
			if( items.length > 2 ) {
				var id = 'army_' + items[0];
				var location = items[1]
				//var click = items[2];
				if( items[2] ) {
					var classes = items[2].split( ' ' );
					//alert( items );
					if( !document.getElementById( id ) ) {
						var parent = document.getElementById( location );
						if( !parent ) {
							parent = document.createElement( 'div' );
							YAHOO.util.Dom.addClass( parent, 'empty-spot' );
							YAHOO.util.Dom.setStyle( parent, 'top', ( Math.floor( location / ( AOS.map.width + 1.0 ) ) * 14 + 3 ) + 'px' );
							YAHOO.util.Dom.setStyle( parent, 'left', ( Math.floor( location % ( AOS.map.width + 1.0 ) ) * 14 + 2 ) + 'px' );
							parent.id = location;
							AOS.map.maptable.appendChild( parent );
						}
						var armies = parent.childNodes.length;
						var addX = 0;
						var addY = 0;
						//alert( "number of armies: " + armies )
						if( armies == 1 || armies > 2 ) {
							addX = 7;
						}
						if( armies > 1 ) {
							addY = 7;
						}
						
						var element = document.createElement( 'div' );
						//YAHOO.util.Event.addListener( element, "click", onClickFunction, click, true );
						for( p in classes ) {
							YAHOO.util.Dom.addClass( element, classes[p] );
						}
						YAHOO.util.Dom.setStyle( element, 'top', addY + 'px' );
						YAHOO.util.Dom.setStyle( element, 'left', addX + 'px' );
						element.id = id;
						parent.appendChild( element );
					}
				}
			}
		}
	}
}

AOS.map.handleSuccessInfo = function( o ) {
	var nodes = o.responseText.split( '@' );
	var counter = 0;
	var id;
	var click;
	var faction_class;
	var inactive;
	for( var i = 0; i < nodes.length; i ++ ) {
		if( nodes[i] ) {
			var tmp = nodes[i].split( '/' );
			if( tmp.length > 1 && tmp[0] == 'armies' ) {
				AOS.map.updateCoords();
				AOS.map.plotArmies( tmp );
				//alert( 'done plotting' );
			}
			else {
				if( counter == 0 ) {
					id = nodes[i];
				}
				else if( counter == 1 ) {
					faction_class = nodes[i];
				}
				else if( counter ==2 ) {
					inactive = nodes[i];
				}
				else if( counter == 3 ) {
					counter = -1;
					if( !document.getElementById( id ) ) {
						var element = document.createElement( 'div' );
						//element.setAttribute( 'class', nodes[i] );
						//YAHOO.util.Event.removeListener( element, "click" );
						//YAHOO.util.Event.addListener( element, "click", onClickFunction, click, true );
						if( faction_class && faction_class != ' ' ) {
							YAHOO.util.Dom.addClass( element, faction_class );
						}
						YAHOO.util.Dom.addClass( element, nodes[i] );
						if( inactive && inactive == 'inactive' ) {
							element.innerHTML = '<img src="../resources/inactive.gif" />';
						}
						var displaceX = 0;
						var displaceY = 0;
						
						if( YAHOO.util.Dom.hasClass( element, "ac" ) || YAHOO.util.Dom.hasClass( element, "ic" ) || YAHOO.util.Dom.hasClass( element, "hc" ) || YAHOO.util.Dom.hasClass( element, "oc" ) ) {
							displaceX = -2;
							displaceY = -2;
						}
						YAHOO.util.Dom.setStyle( element, 'top', ( Math.floor( id / ( AOS.map.width + 1.0 ) ) * 14 + 3 + displaceX ) + 'px' );
						YAHOO.util.Dom.setStyle( element, 'left', ( Math.floor( id % ( AOS.map.width + 1.0 ) ) * 14 + 2 + displaceY ) + 'px' );
						element.id = id;
						AOS.map.maptable.appendChild( element );
					}
					else {
						//alert( 'already exists: ' + id );
					}
				}
				counter ++;
			}
		}
	}
	AOS.map.updateMapImageTiles();
}

AOS.map.handleFailureInfo = function( o ) {
	AOS.map.coords.innerHTML = "Error retrieving map information! You can drag the map a little to try again, if this doens't work try refreshing the page.";
}

AOS.map.infoCallback = {
	success: AOS.map.handleSuccessInfo, 
	failure: AOS.map.handleFailureInfo
};


AOS.map.onClickFunction = function ( event, obj ) {
	eval( obj );
};

AOS.map.getSquareInfo = function( xGet, yGet ) {
	if( xGet == 'complete' ) {
		xGet = AOS.map.xSelected;
		yGet = AOS.map.ySelected;
	}
	var mapinfo = document.getElementById( "mapinfo" );
  	if( mapinfo ) {
  		mapinfo.innerHTML = "<br /><br /><br /><br /><div id='text_center'><img src=\"../resources/load.gif\" /> Loading...</div><br /><br /><br /><br />";
  	}
  	YAHOO.util.Connect.asyncRequest( 'GET', 'get_village.php?' + "x=" + xGet + "&y=" + yGet, AOS.map.villageCallback, null );
}

AOS.map.handleSuccessVillage = function( o ) {
	//alert( o.responseText );
  	var mapinfo = document.getElementById( "mapinfo" );
  	if( mapinfo ) {
  		mapinfo.innerHTML = o.responseText;
  		initializeTooltips();
	}
}

AOS.map.handleFailureVillage = function( o ) {
	AOS.map.coords.innerHTML = "<div id='text_center'>Problem loading village information, please try again.</div>";
}

AOS.map.villageCallback = {
	success: AOS.map.handleSuccessVillage, 
	failure: AOS.map.handleFailureVillage
};

AOS.map.moveMapInDirection = function ( direction ) {
	var xCalc = AOS.map.x;
	var yCalc = AOS.map.y;
	if( direction == "north" ) {
		xCalc += 20;
		yCalc -= 60;
	}
	else if( direction == "north-east" ) {
		xCalc += 60;
		yCalc -= 20;
	}
	else if( direction == "east" ) {
		xCalc += 60;
		yCalc += 20;
	}
	else if( direction == "south-east" ) {
		xCalc += 60;
		yCalc += 60;
	}
	else if( direction == "south" ) {
		xCalc += 20;
		yCalc += 60;
	}
	else if( direction == "south-west" ) {
		xCalc -= 60;
		yCalc += 60;
	}
	else if( direction == "west" ) {
		xCalc -= 60;
		yCalc += 20;
	}
	else if( direction == "north-west" ) {
		xCalc -= 20;
		yCalc -= 20;
	}
	
	if( xCalc < 0 ) { 
		xCalc = 0;
	}
	else if( xCalc > AOS.map.width ) { 
		xCalc = AOS.map.width;
	}
	if( yCalc < 0 ) { 
		yCalc = 0;
	}
	else if( yCalc > AOS.map.height ) { 
		yCalc = AOS.map.height;
	}
	
	AOS.map.moveMapTo( xCalc, yCalc );
}

AOS.map.moveMapTo = function( xCalc, yCalc ) {

	// Set global variable to be able to retrieve village information about the newly selected square
	AOS.map.xSelected = xCalc;
	AOS.map.ySelected = yCalc;
	
	if( !AOS.map.mapSquareSelector ) {
		AOS.map.mapSquareSelector = document.createElement( "div" );
		YAHOO.util.Dom.addClass( AOS.map.mapSquareSelector, "square-selector" );
		AOS.map.maptable.appendChild( AOS.map.mapSquareSelector );
	}
	
	YAHOO.util.Dom.setX( AOS.map.mapSquareSelector, Math.round( AOS.map.xSelected * 14 ) + YAHOO.util.Dom.getX( AOS.map.maptable ) - 1 );
	YAHOO.util.Dom.setY( AOS.map.mapSquareSelector, Math.round( AOS.map.ySelected * 14 ) + YAHOO.util.Dom.getY( AOS.map.maptable ) + 0 );
	
	xCalc -= 20;
	yCalc -= 20;
	// Change to left and top values
	if( xCalc < 0 ) {
		xCalc = 0;
	}
	else if( xCalc > AOS.map.width - 39 ) {
		xCalc = AOS.map.width - 39;
	}
	
	if( yCalc < 0 ) {
		yCalc = 0;
	}
	else if( yCalc > AOS.map.height - 39 ) {
		yCalc = AOS.map.height - 39;
	}
	
	// Set global variable to be able to retrieve villages and armies for the new location
	AOS.map.x = xCalc;
	AOS.map.y = yCalc;
	xCalc = xCalc * -14;
	yCalc = yCalc * -14;
	var mapAnimation = new YAHOO.util.Anim( AOS.map.maptable, { 
		left: { to: xCalc },
		top: { to: yCalc }
	}, 0.8, YAHOO.util.Easing.easeBoth );
	mapAnimation.onComplete.subscribe( AOS.map.addInformation );
	mapAnimation.onComplete.subscribe( AOS.map.getSquareInfo );
	mapAnimation.onComplete.subscribe( AOS.map.updateMapImageTiles );
	mapAnimation.animate();
}

AOS.map.addLocation = function( x, y ) {
	YAHOO.util.Connect.asyncRequest( 'POST', 'add_location.php', { 
		success: function( o ) {
			document.getElementById( "locations-list" ).innerHTML = o.responseText;
		}, 
		failure: function( o ) {} }, 
		"x=" + x + "&y=" + y );
}

AOS.map.updateMapImageTiles = function() {
	var imagedTiles;
	var className;
	var classNameNoImage;
	
	var sectorX = Math.floor( ( AOS.map.x + 20 ) / AOS.map.sectorWidth );
	var sectorY = Math.floor( ( AOS.map.y + 20 ) / AOS.map.sectorHeight );

	var tiles = YAHOO.util.Dom.getElementsByClassName( "sectorBorder", "div", AOS.map.maptable );
	
	var imageSectors = Array();
	for( var i = 0; i < 3; i ++ ) {
		for( var p = 0; p < 3; p ++ ) {
			imageSectors[i * 3 + p] =  ( sectorX - 1 + p ) + ( sectorY - 1 + i ) * AOS.map.sectorsPerRow;
		}
	}
	
	for( var i = 0; i < 3; i ++ ) {
		className = "empty-sector-" + ( i + 1 );
		classNameNoImage = "empty-sector-" + ( i + 1 ) + "-no-image";
		imagedTiles = YAHOO.util.Dom.getElementsByClassName( className, "div", AOS.map.maptable );
		YAHOO.util.Dom.replaceClass( imagedTiles, className, classNameNoImage );
		className = "full-sector-" + ( i + 1 );
		classNameNoImage = "full-sector-" + ( i + 1 ) + "-no-image";
		imagedTiles = YAHOO.util.Dom.getElementsByClassName( className, "div", AOS.map.maptable );
		YAHOO.util.Dom.replaceClass( imagedTiles, className, classNameNoImage );
	}
	
	var hit = 0;
	for( var i = 0; i < tiles.length; i ++ ) {
		for( var p = 0; p < imageSectors.length; p ++ ) {
			// Need to replace this one
			if( i == imageSectors[p] ) {
				for( var q = 1; q < 4; q ++ ) {
					className = "empty-sector-" + q;
					classNameNoImage = "empty-sector-" + q + "-no-image";
					if( YAHOO.util.Dom.hasClass( tiles[i], classNameNoImage ) ) {
						YAHOO.util.Dom.replaceClass( tiles[i], classNameNoImage, className );
					}
					else {
						className = "full-sector-" + q;
						classNameNoImage = "full-sector-" + q + "-no-image";
						if( YAHOO.util.Dom.hasClass( tiles[i], classNameNoImage ) ) {
							YAHOO.util.Dom.replaceClass( tiles[i], classNameNoImage, className );
						}
					}
				}
				hit ++;
			}
		}
		if( hit == 9 ) {
			break;
		}
	}
}

AOS.map.onVisibilityChange = function() {
	var oldRanges = YAHOO.util.Dom.getElementsByClassName( "visibility-range", "div", AOS.map.maptable );

	if( oldRanges.length > 0 ) {
		for( var i in oldRanges ) {
			var animation = new YAHOO.util.Anim( oldRanges[i], { opacity: { from: 0.15, to: 0 } }, 1, YAHOO.util.Easing.easeNone() );
			if( i == oldRanges.length - 1 ) {
				animation.onComplete.subscribe( AOS.map.startVisibilityChange );
			}
			animation.animate();
		}
	}
	else {
		AOS.map.startVisibilityChange();
	}
}

AOS.map.startVisibilityChange = function() {
	var selected = document.getElementById( "visibility-select" );

	if( selected && ( selected.value == "ruler" || selected.value == "faction" ) ) {
		YAHOO.util.Connect.asyncRequest( "GET", "get_visibility.php?for=" + selected.value, AOS.map.getVisibilityCallback, null );
	}

	var oldRanges = YAHOO.util.Dom.getElementsByClassName( "visibility-range", "div", AOS.map.maptable );
	for( var i in oldRanges ) {
		AOS.map.maptable.removeChild( oldRanges[i] );
	}
}

AOS.map.getVisibilitySuccess = function( response ) {
	var visibility;
	try {
		visibility = YAHOO.lang.JSON.parse( response.responseText );
	} catch( error ) {
		alert( "Unable to parse visibility information." );
	}
	
	if( visibility ) {
		for( var i in visibility ) {
			var range = document.createElement( "div" );
			YAHOO.util.Dom.addClass( range, "visibility-range" );
			YAHOO.util.Dom.setStyle( range, "left", ( visibility[i].x * 14 + 2 - 14 * ( visibility[i].range - 0 ) ) + "px" );
			YAHOO.util.Dom.setStyle( range, "top", ( visibility[i].y * 14 + 3 - 14 * ( visibility[i].range - 0 ) ) + "px" );
			YAHOO.util.Dom.setStyle( range, "width", ( 28 * ( visibility[i].range + 0.5 ) - 4 ) + "px" );
			YAHOO.util.Dom.setStyle( range, "height", ( 28 * ( visibility[i].range + 0.5 ) - 4 ) + "px" );
			YAHOO.util.Dom.setStyle( range, "opacity", "0" );
			AOS.map.maptable.appendChild( range );
			var animation = new YAHOO.util.Anim( range, { opacity: { from: 0, to: 0.15 } }, 1, YAHOO.util.Easing.easeNone() );
			animation.animate();
		}
	}
}

AOS.map.getVisibilityCallback = {
	success: AOS.map.getVisibilitySuccess
}
